import { Component, HostListener, OnDestroy, OnInit } from "@angular/core";
import { sjgzxinModuledatas } from "../pubcomponent/pageTitle.datas";
import { LocalStorageService } from "../local-storage-service";
import { CommService } from "../comm-service";
import { MyhttpService } from "../myhttp.service";
import { FormBuilder, FormGroup } from "@angular/forms";
import { MyValidator } from "../myvalidator-util";
import { FileItem, FileLikeObject, FileUploader, ParsedResponseHeaders } from "ng2-file-upload";

declare var $: any;

@Component({
  template: `
  <div class="all_bg paddingTop">
    <div class="">
      <div class="marginBottom">
        <ng-container *ngIf="actionobj1.length">
          <portlet-action class="actions" [o]="actionobj1" (outhander)="actionHander($event)"></portlet-action>
        </ng-container>
      </div>
      <div class="portlet-body">
        <div class="row">
          <div class="col-lg-12">
            <div class="tabbable-custom nav-justified">
              <ul class="nav nav-tabs nav-justified">
                <li class="active"><a href="#ztxx" data-toggle="tab" (click)="tabToggle('ztxx')">状态信息</a>
                  <!-- <div class="arrdowm"></div> -->
                </li>
                <li><a href="#glsjb" data-toggle="tab" (click)="tabToggle('glsjb')">关联试卷包</a>
                  <!-- <div class="arrdowm"></div> -->
                </li>
              </ul>
              <div class="tab-content">
                <!--状态信息-->
                <div class="tab-pane active" id="ztxx">
                  <div class="row">
                    <form class="form-horizontal" role="form">
                      <div class="col-lg-4 col-lg-offset-3">
                        <div class="form-group">
                          <label class="col-lg-5 control-label">标签id：</label>
                          <div class="col-lg-7">
                            <input type="text" class="form-control" name="id" [(ngModel)]="s_obj.id"/>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="col-lg-5 control-label">gps开关状态：</label>
                          <div class="col-lg-7">
                            <select class="form-control" name="gpskgzt" id="gpskqztSelect2"
                                    [(ngModel)]="s_obj.gpskgzt" (change)="inittable_dzbqsb_ztxx()"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-1">
                        <button class="btn blue" (click)="inittable_dzbqsb_ztxx()">
                          <i class="fa fa-search"></i> 搜索
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="row">
                    <div class="col-lg-12" *ngIf="table_dzbq_ztxx">
                      <my-table [o]="table_dzbq_ztxx"></my-table>
                    </div>
                  </div>
                </div>
                <!--关联试卷包-->
                <div class="tab-pane" id="glsjb">
                  <div class="row">
                    <form class="form-horizontal" role="form">
                      <div class="col-lg-3">
                        <div class="form-group">
                          <label class="col-lg-5 control-label">标签id：</label>
                          <div class="col-lg-7">
                            <input type="text" class="form-control" name="id" [(ngModel)]="s_obj_glxx.id"/>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="col-lg-5 control-label">gps开关状态：</label>
                          <div class="col-lg-7">
                            <select class="form-control" name="gpskgzt" id="gpskqztSelect"
                                    [(ngModel)]="s_obj_glxx.gpskgzt" (change)="inittable_dzbqsb_glxx()"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group">
                          <label class="col-lg-5 control-label">是否关联试卷包：</label>
                          <div class="col-lg-7">
                            <select class="form-control" name="sfglsjb" id="sfglsjbSelect"
                                    [(ngModel)]="s_obj_glxx.sfglsjb" (change)="inittable_dzbqsb_glxx()"></select>
                          </div>
                        </div>
                      </div>
                      <div class="col-lg-1">
                        <button class="btn blue" (click)="inittable_dzbqsb_glxx()">
                          <i class="fa fa-search"></i> 搜索
                        </button>
                      </div>
                    </form>
                  </div>
                  <div class="row">
                    <div class="col-lg-12" *ngIf="table_dzbq_glxx">
                      <my-table [o]="table_dzbq_glxx"></my-table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="xq_bqsbModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">详情</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-12" *ngIf="xqobj_bqsb">
                <xq-form [o]="xqobj_bqsb"></xq-form>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">确 定</button>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="add_bqsbModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">{{modaltitle}}</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <form class="form-horizontal" role="form" [formGroup]="formgroup_bqsb">
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      标签ID:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="id" formControlName="idCtr"/>
                      <div
                        *ngIf="formgroup_bqsb.get('idCtr').invalid&&formgroup_bqsb.get('idCtr').dirty">
                          <span *ngIf="formgroup_bqsb.hasError('myrequire','idCtr')">
                                <tool-tip [o]="formgroup_bqsb.getError('myrequire','idCtr').msg"></tool-tip>
                          </span>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      型号:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="xh" formControlName="xhCtr"/>
                      <div
                        *ngIf="formgroup_bqsb.get('xhCtr').invalid&&formgroup_bqsb.get('xhCtr').dirty">
                          <span *ngIf="formgroup_bqsb.hasError('myrequire','xhCtr')">
                                <tool-tip [o]="formgroup_bqsb.getError('myrequire','xhCtr').msg"></tool-tip>
                          </span>
                      </div>
                    </div>
                  </div>
                </div>
              </form>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="sure_bqsb()">确 定</button>
          </div>
        </div>
      </div>
    </div>
    <div class="modal fad" id="glsjb_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog bigmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">关联试卷包</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <form class="form-horizontal" role="form">
                <div class="col-lg-3">
                  <div class="form-group">
                    <label class="control-label col-lg-5">试卷包名称：</label>
                    <div class="col-lg-7">
                      <input type="text" class="form-control" name="sjbmc" [(ngModel)]="s_obj_sjb.sjbmc"/>
                    </div>
                  </div>
                </div>
                <div class="col-lg-4">
                  <div class="form-group">
                    <label class="control-label col-lg-5">目的考区名称:</label>
                    <div class="col-lg-7">
                      <input type="text" class="form-control" name="mdkqmc" [(ngModel)]="s_obj_sjb.mdkqmc"/>
                    </div>
                  </div>
                </div>
                <div class="col-lg-4">
                  <div class="form-group">
                    <label class="control-label col-lg-5 ">目的考点名称：</label>
                    <div class="col-lg-7">
                      <input type="text" class="form-control" name="mdkdmc" [(ngModel)]="s_obj_sjb.mdkdmc"/>
                    </div>
                  </div>
                </div>
                <div class="col-lg-1">
                  <button type="button" class="btn blue" (click)="inittable_sjb()">
                    <i class="fa fa-search"></i> 搜索
                  </button>
                </div>
              </form>
            </div>
            <div class="row">
              <div class="col-lg-12" *ngIf="table_sjb">
                <my-table [o]="table_sjb"></my-table>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="sure_glsjb()">确 定</button>
          </div>
        </div>
      </div>
    </div>

    <div class="modal fad" id="cspz_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">电子标签参数配置</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <form class="form-horizontal" role="form" [formGroup]="formgroup_cspz">
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      mqtt服务器ip：
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="mqttfwqip" formControlName="mqttfwqipCtr"/>
                      <span class="text-danger help-block">(默认47.111.5.196)</span>
                      <div *ngIf="formgroup_cspz.get('mqttfwqipCtr').invalid&&formgroup_cspz.get('mqttfwqipCtr').dirty">
                        <div *ngIf="formgroup_cspz.hasError('isIp','mqttfwqipCtr')">
                          <tool-tip [o]="formgroup_cspz.getError('isIp','mqttfwqipCtr').msg"></tool-tip>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      运动阈值:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="ydyz" formControlName="ydyzCtr"/>
                      <span class="text-danger help-block">(0-127，默认32)</span>
                      <div *ngIf="formgroup_cspz.get('ydyzCtr').invalid&&formgroup_cspz.get('ydyzCtr').dirty">
                        <div *ngIf="formgroup_cspz.hasError('numberrange','ydyzCtr')">
                          <tool-tip [o]="formgroup_cspz.getError('numberrange','ydyzCtr').msg"></tool-tip>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      cat1询问间隔:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="cat1xwjg" formControlName="cat1xwjgCtr"/>
                      <span class="text-danger help-block">(0-524287，默认3600)</span>
                      <div *ngIf="formgroup_cspz.get('cat1xwjgCtr').invalid&&formgroup_cspz.get('cat1xwjgCtr').dirty">
                        <div *ngIf="formgroup_cspz.hasError('numberrange','cat1xwjgCtr')">
                          <tool-tip [o]="formgroup_cspz.getError('numberrange','cat1xwjgCtr').msg"></tool-tip>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      cat1开启后上报间隔:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="cat1kqhsbjg" formControlName="cat1kqhsbjgCtr"/>
                      <span class="text-danger help-block">(0-524287，默认60)</span>
                      <div
                        *ngIf="formgroup_cspz.get('cat1kqhsbjgCtr').invalid&&formgroup_cspz.get('cat1kqhsbjgCtr').dirty">
                        <div *ngIf="formgroup_cspz.hasError('numberrange','cat1kqhsbjgCtr')">
                          <tool-tip [o]="formgroup_cspz.getError('numberrange','cat1kqhsbjgCtr').msg"></tool-tip>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      蓝牙广播间隔:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="lygbjg" formControlName="lygbjgCtr"/>
                      <span class="text-danger help-block">(0-127，默认1)</span>
                      <div *ngIf="formgroup_cspz.get('lygbjgCtr').invalid&&formgroup_cspz.get('lygbjgCtr').dirty">
                        <div *ngIf="formgroup_cspz.hasError('numberrange','lygbjgCtr')">
                          <tool-tip [o]="formgroup_cspz.getError('numberrange','lygbjgCtr').msg"></tool-tip>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      蓝牙发射功率:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="lyfsgl" formControlName="lyfsglCtr"/>
                      <span class="text-danger help-block">(0-8，默认0)</span>
                      <div *ngIf="formgroup_cspz.get('lyfsglCtr').invalid&&formgroup_cspz.get('lyfsglCtr').dirty">
                        <div *ngIf="formgroup_cspz.hasError('numberrange','lyfsglCtr')">
                          <tool-tip [o]="formgroup_cspz.getError('numberrange','lyfsglCtr').msg"></tool-tip>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-12">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      ADC检测间隔:
                    </label>
                    <div class="col-lg-8">
                      <input type="text" class="form-control" name="adcjcjg" formControlName="adcjcjgCtr"/>
                      <span class="text-danger help-block">(1-65535小时，默认1)</span>
                      <div *ngIf="formgroup_cspz.get('adcjcjgCtr').invalid&&formgroup_cspz.get('adcjcjgCtr').dirty">
                        <div *ngIf="formgroup_cspz.hasError('numberrange','adcjcjgCtr')">
                          <tool-tip [o]="formgroup_cspz.getError('numberrange','adcjcjgCtr').msg"></tool-tip>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </form>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="cspz_sure()">确 定</button>
          </div>
        </div>
      </div>
    </div>

    <div class="modal fad" id="pldr_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">批量导入</h4>
          </div>
          <div class="modal-body">
            <form class="form-horizontal" role="form">
              <div class="row">
                <div class="col-lg-9">
                  <div class="form-group">
                    <label class="control-label col-lg-3">
                      <require-label></require-label>
                      文件:</label>
                    <div class="col-lg-9">
                      <input *ngIf="showUploader" class="form-control ngselectFileInput" type="file" ng2FileSelect
                             [uploader]="uploader"
                             (change)="selectedFileOnChanged($event)"/>
                      <div class="input-group selectFile">
                        <div class="input-icon">
                          <input class="form-control" type="text" name="filename" readonly
                                 [value]="nowfilename">
                        </div>
                        <span class="input-group-btn">
                          <button class="btn btn-success" type="button"><i class="fa fa-file"></i> 选择</button>
                  </span>
                      </div>
                      <div *ngIf="filewarnflag">
                        <span class="help-block text-danger">{{filewarntext}}</span>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-lg-3">
                  <label class="control-label text-danger">
                    <a href="dzbqpldr.xlsx" download="批量新增模板下载.xlsx">批量新增模板下载</a>
                  </label>
                </div>
              </div>
            </form>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
            <button type="button" class="btn btn-primary" (click)="pldrDone()">确 定</button>
          </div>
        </div>
      </div>
    </div>


    <div class="modal fad" id="viewglxx_Modal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
      <div class="modal-dialog smmodalwidth" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">关联试卷包信息</h4>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-12">
                <table class="table table-bordered">
                  <thead>
                  <tr>
                    <th>试卷包名称</th>
                  </tr>
                  </thead>
                  <tbody *ngIf="glsjbxxList.length">
                  <tr *ngFor="let row of glsjbxxList">
                    <td>{{row.sjbmc}}</td>
                  </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
          </div>
        </div>
      </div>
    </div>
    </div>
    
  `,
  styles: [
    ".ngselectFileInput{display: none}"
  ]
})
export class BqsbglComponent implements OnInit, OnDestroy {
  pagetitleobj: any;
  userinfo: any;
  s_ksjhbh: string = "";
  bqsb_btns: any[] = ["bqsb_gpsonN", "bqsb_gpsoffN", "bqsb_add", "bqsb_refresh", "bqsb_plpzcs", "bqsb_removeN", "bqsb_dr"];
  bqsb_c_btns: any[] = ["edite_bqsb", "remove_bqsb", "xq_bqsb", "glkz_bqsb", "gpskz_bqsb", "ckglxx_bqsb"];
  hascbtns: any[] = [];
  actionobj1: any[] = [];
  activetab: string = "ztxx";
  s_obj: any = {
    sfglsjb: "",  //是否关联试卷包  0 --已关联   1- 未关联   ""-全部
    gpskgzt: "",  //gps开关状态        0---未开启   1--已开启  "" -全部
    ksjhbh: "", // 状态信息的不传考试计划
    id: "", // 标签id
  }
  table_dzbq_ztxx: any;
  s_obj_glxx: any = {
    sfglsjb: "1",  //是否关联试卷包  0 --/sjgz/sbpz/pzdzbqcs已关联   1- 未关联   ""-全部
    gpskgzt: "", //gps开关状态        0---未开启   1--已开启  "" -请选择
    ksjhbh: "",
    id: "", // 标签id
  }
  selectDefaultField: any = {
    sfglsjb: "",
    gpskgzt: '',// 关联tab的
    gpskgzt2: "", // 状态信息tab的
  };
  table_dzbq_glxx: any;
  caozuo_dzbqbh: string = "";
  xqobj_bqsb: any;
  formgroup_bqsb: FormGroup;
  modalflag: string = "";
  modaltitle: string = "";
  editeFixedField: any = {
    sfqy: "",
    gpskgzt: ''
  };
  s_obj_sjb: any = {
    sjbmc: "",
    ksjhbh: "",
    mdkqmc: "",
    mdkdmc: "",
    sjgldzbq: "1"  //是否关联电子标签：0 已关联；1 未关联。
  };
  table_sjb: any;
  noReativeFormField: any = {
    dzbqList: []  //批量设置电子标签参数
  };
  formgroup_cspz: FormGroup;
  // 批量导入 电子标签
  uploader: FileUploader;
  nowfilename: string = "";
  nowfile: FileItem;
  filewarnflag: boolean = false;
  filewarntext: string = "";
  showUploader: boolean = true;
  glsjbxxList: any[] = [];

  /**
   * 初始化按钮
   */
  initactions(): void {
    // this.commservice.getroleBtns(this.bqsb_btns, this.bqsb_c_btns, this.userinfo.nowroleid, "tablebqsb", (hasportbtns, hastablebtns) => {
    //   this.actionobj1 = hasportbtns;
    //   this.hascbtns = hastablebtns;
    // });
    this.commservice.getroleBtns_not_permissions(this.bqsb_btns, this.bqsb_c_btns, "tablebqsb", (hasportbtns, hastablebtns) => {
      this.actionobj1 = hasportbtns;
      this.hascbtns = hastablebtns;
      console.log(this.actionobj1);

    });
  }

  /**
   * 按钮的处理回调
   * @param e
   */
  actionHander(e: any): void {
    const fromv = e.pfrom;
    const actiontype = e.type;
    if (fromv === "tablebqsb") {
      if (actiontype === "refresh") {
        // 刷新
        if (this.activetab == "ztxx") {
          this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
        } else {
          this.table_dzbq_glxx = Object.assign({}, this.table_dzbq_glxx);
        }
      } else if (actiontype === "add") {
        // 添加
        this.add_bqsb();
      } else if (actiontype == "gpsonN") {
        // 批量开启 gps
        this.gpsztCtr("1");
      } else if (actiontype == "gpsoffN") {
        // 批量关闭gps
        this.gpsztCtr("0");
      } else if (actiontype == "plpzcs") {
        // 批量配电子标签参数
        this.plpzdzbqcs();
      } else if (actiontype == "removeN") {
        // 批量删除
        const selectrows = $("#table_dzbq_ztxx").bootstrapTable("getSelections");
        if (selectrows.length == 0) {
          this.commservice.myswal("warning", "请选择删除的数据", "", "ts", null);
          return;
        }
        this.removeN_bqsb(selectrows);
      } else if (actiontype == "dr") {
        this.pldr();
      }
    }
  }

  /**
   * 批量删除
   * @param selectrows
   */
  removeN_bqsb(selectrows: any): void {
    this.commservice.myswal("warning", "确认删除?", "", "cz", () => {
      const dzbqbhsv = selectrows.map((item) => {
        return item.dzbqbh;
      });
      const url = "sjgz/jcsj/dzbqsbsc";
      this.itservice.kwPtPost(url, {
        dzbqbhs: dzbqbhsv
      }).subscribe(resp => {
        this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
          if (arg1) {
            if (arg2) {
              this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
              this.commservice.myswal("success", resp, "", "ts", null);
            } else {
              this.commservice.myswal("warning", resp, "", "ts", null);
            }
          } else {
            this.removeDone_bqsb();
          }
        });
      })
    })
  }

  /**
   * 批量导入电子标签
   */
  pldr(): void {
    this.showUploader = false;
    this.nowfilename = "";
    this.nowfile = null;
    this.filewarnflag = false;
    setTimeout(() => {
      this.showUploader = true;
      setTimeout(() => {
        $("#pldr_Modal").find(".selectFile")[0].onclick = function () {
          $("#pldr_Modal").find(".ngselectFileInput").click();
        };
        $("#pldr_Modal").modal({
          keyboard: true,
          backdrop: "static"
        });
      }, 200)
    }, 200);
  }

  /**
   * 批量控制gps的开关状态
   * 0---关闭
   * 1--开启
   */
  gpsztCtr(ztv: string): void {
    const selectrows = $("#table_dzbq_ztxx").bootstrapTable("getSelections");
    if (!selectrows.length) {
      this.commservice.myswal("warning", "请选择处理数据", "", "ts", null);
      return
    }
    const dzbqbhsListv = selectrows.map((item) => {
      return item.dzbqbh
    });
    const url = "sjgz/sbpz/dzbqSzgpszt";
    this.itservice.kwPtPost(url, {
      gpskgzt: ztv,
      dzbqbhs: dzbqbhsListv
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.gpsztCtr(ztv);
        }
      });
    })

  }

  /**
   * 批量配置 电子标签参数
   */
  plpzdzbqcs(): void {
    const selectrows = $("#table_dzbq_ztxx").bootstrapTable("getSelections");
    if (!selectrows.length) {
      this.commservice.myswal("warning", "请选择处理数据", "", "ts", null);
      return
    }
    this.noReativeFormField.dzbqList = selectrows.map((item) => {
      return {
        dzbqbh: item.dzbqbh,
        id: item.id
      }
    });
    // 还原表单
    this.formgroup_cspz.patchValue({
      mqttfwqipCtr: "47.111.5.196",
      ydyzCtr: 32,
      cat1xwjgCtr: 3600,
      cat1kqhsbjgCtr: 60,
      lygbjgCtr: 1,
      lyfsglCtr: 0,
      adcjcjgCtr: 1
    });
    $("#cspz_Modal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  createformgroup_cspz(): void {
    this.formgroup_cspz = this.fb.group({
      mqttfwqipCtr: ["", [this.myValidator.isIp(true)]],
      ydyzCtr: ["", [this.myValidator.isNumberRange(true, 0, 127)]],
      cat1xwjgCtr: ["", [this.myValidator.isNumberRange(true, 0, 524287)]],
      cat1kqhsbjgCtr: ["", [this.myValidator.isNumberRange(true, 0, 524287)]],
      lygbjgCtr: ["", [this.myValidator.isNumberRange(true, 0, 127)]],
      lyfsglCtr: ["", [this.myValidator.isNumberRange(true, 0, 8)]],
      adcjcjgCtr: ["", [this.myValidator.isNumberRange(true, 1, 65535)]]
    });
  }

  /**
   * 电子标签参数配置， 验证+ 保存
   */
  cspz_sure(): void {
    if (this.formgroup_cspz.invalid) {
      const ctrols = this.formgroup_cspz.controls;
      for (let path in ctrols) {
        ctrols[path].markAsDirty();
        ctrols[path].updateValueAndValidity();
      }
      return
    }
    const formgroupv = this.formgroup_cspz.getRawValue();
    const mqttfwqipv = this.commservice.removeSpace(true, formgroupv.mqttfwqipCtr);
    const ydyzv = this.commservice.removeSpace(true, formgroupv.ydyzCtr);
    const cat1xwjgv = this.commservice.removeSpace(true, formgroupv.cat1xwjgCtr);
    const cat1kqhsbjgv = this.commservice.removeSpace(true, formgroupv.cat1kqhsbjgCtr);
    const lygbjgv = this.commservice.removeSpace(true, formgroupv.lygbjgCtr);
    const lyfsglv = this.commservice.removeSpace(true, formgroupv.lyfsglCtr);
    const adcjcjgv = this.commservice.removeSpace(true, formgroupv.adcjcjgCtr);
    this.commservice.blockUI({
      boxed: true,
      message: "设置中...",
      zIndex: 10051,
      overlayColor: "#67809F"
    });
    const url = "sjgz/sbpz/pzdzbqcs";
    this.itservice.kwPtPost(url, {
      mqttfwqip: mqttfwqipv,
      ydyz: ydyzv,
      cat1xwjg: cat1xwjgv,
      cat1kqhsbjg: cat1kqhsbjgv,
      lygbjg: lygbjgv,
      lyfsgl: lyfsglv,
      adcjcjg: adcjcjgv,
      dzbqList: this.noReativeFormField.dzbqList
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
            $("#cspz_Modal").modal("hide");
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.cspz_sure();
        }
      });
    });
  }

  /**
   * 添加标签设备
   */
  add_bqsb(): void {
    this.modalflag = "add";
    this.modaltitle = "添加标签设备";
    this.formgroup_bqsb.reset();
    $("#add_bqsbModal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  tabToggle(activeTab: string): void {
    this.activetab = activeTab;
    if (this.activetab == "ztxx") {
      $("#gpskqztSelect2").selectpicker("val", this.selectDefaultField.gpskgzt2);
      this.s_obj.gpskgzt = this.selectDefaultField.gpskgzt2;
      this.s_obj.id = "";
      this.inittable_dzbqsb_ztxx();
    } else if (this.activetab == "glsjb") {
      $("#gpskqztSelect").selectpicker("val", this.selectDefaultField.gpskgzt);
      $("#sfglsjbSelect").selectpicker("val", this.selectDefaultField.sfglsjb);
      this.s_obj_glxx.gpskgzt = this.selectDefaultField.gpskgzt; //gps开启状态
      this.s_obj_glxx.sfglsjb = this.selectDefaultField.sfglsjb; // 是否关联试卷包
      this.s_obj_glxx.id = "";
      this.inittable_dzbqsb_glxx();
    }
  }

  /**
   * 电子标签设备， ---状态信息表格
   */
  inittable_dzbqsb_ztxx(): void {
    const that = this;
    this.table_dzbq_ztxx = {
      tableid: "table_dzbq_ztxx",
      url: "sjgz/jcsj/dzbqsblb",
      reqobj: this.s_obj,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "dzbqsbList",
      columns: [{
        checkbox: true
      }, {
        title: '序号',
        field: 'ordernum',
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "标签ID",
        field: "id",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "型号",
        field: "xh",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "故障状态",
        field: "gzzt",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        },
        formatter: function (v) {
          let retstr: string = "";
          if (v == "0") {
            retstr = "正常";
          } else if (v == "1") {
            retstr = "异常";
          }
          return retstr;
        }
      }, {
        title: "是否启用",
        field: "sfqy",
        events: this.myevents,
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        },
        formatter: function (v) {
          let str = "";
          if (v === "1") {
            // 已启用
            str = "<span style='color: blue;font-size: 20px;cursor: pointer' class='toggle'><i class='fa fa-toggle-on' aria-hidden='true'></i></span>&nbsp;&nbsp;<span style='color: blue;font-size: 20px;'></span>";
          } else if (v == "0") {
            // 未启用
            str = "<span style='color:black;font-size: 20px;cursor: pointer' class='toggle'><i class='fa fa-toggle-off' aria-hidden='true'></i></span>";
          }
          return str;
        }
      }, {
        title: "gps状态",
        field: "gpskgzt",
        events: this.myevents,
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        },
        formatter: function (v) {
          let str = "";
          if (v === "1") {
            // 已开启
            str = "<span style='color: blue;font-size: 20px;cursor: pointer' class='toggle_gps'><i class='fa fa-toggle-on' aria-hidden='true'></i></span>&nbsp;&nbsp;<span style='color: blue;font-size: 20px;'></span>";
          } else if (v == "0") {
            // 未开启
            str = "<span style='color:black;font-size: 20px;cursor: pointer' class='toggle_gps'><i class='fa fa-toggle-off' aria-hidden='true'></i></span>";
          }
          return str;
        }
      }, {
        title: "在线状态",
        field: "zxzt",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        },
        formatter: function (v) {
          let retstr: string = "";
          if (v == "0") {
            retstr = "<span style='color: #1caf9a'><i class='fa fa-circle'></i></span>"
          } else if (v == "1") {
            retstr = "<span style='color: grey'><i class='fa fa-circle'></i></span>"
          }
          return retstr;
        }
      }, {
        title: "gnss电量",
        field: "gnssdl",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        }
      }, {
        title: "蓝牙电量",
        field: "lydl",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "操作",
        field: "dzbqbh",
        events: this.myevents,
        formatter: function (v) {
          let str = "";
          if (that.hascbtns.indexOf("edite_bqsb") != -1) {
            str += "<button type='button' class='btn btn-xs btn-primary edite_bqsb'><i class='fa fa-pencil'></i> 编辑</button>";
          }
          if (that.hascbtns.indexOf("remove_bqsb") != -1) {
            str += "<button type='button' class='btn btn-xs btn-warning remove_bqsb'><i class='fa fa-trash'></i> 删除</button>";
          }
          if (that.hascbtns.indexOf("xq_bqsb") != -1) {
            str += "<button type='button' class='btn btn-xs btn-info xq_bqsb'><i class='fa fa-search'></i> 详情</button>";
          }
          return str;
        }
      }]
    };
    // this.table_dzbq_ztxx.pageSize = 50;
    // this.table_dzbq_ztxx.pageList = [50];
    // this.table_dzbq_ztxx.hiddenPageinfoLink = true;
    // this.table_dzbq_ztxx.paginationLoop = true;
    // this.table_dzbq_ztxx.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.table_dzbq_ztxx.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    // this.table_dzbq_ztxx.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    this.table_dzbq_ztxx.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
  }

  /**
   * 电子标签设备， ----关联试卷包信息表格
   */
  inittable_dzbqsb_glxx(): void {
    const that = this;
    this.table_dzbq_glxx = {
      tableid: "table_dzbq_glxx",
      url: "sjgz/jcsj/dzbqsblb",
      reqobj: this.s_obj_glxx,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "dzbqsbList",
      columns: [{
        checkbox: true,
        visible: false
      }, {
        title: '序号',
        field: 'ordernum',
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "标签ID",
        field: "id",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "型号",
        field: "xh",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "故障状态",
        field: "gzzt",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        },
        formatter: function (v) {
          let retstr: string = "";
          if (v == "0") {
            retstr = "正常";
          } else if (v == "1") {
            retstr = "异常";
          }
          return retstr;
        }
      }, {
        title: "在线状态",
        field: "zxzt",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        },
        formatter: function (v) {
          let retstr: string = "";
          if (v == "0") {
            retstr = "<span style='color: #1caf9a'><i class='fa fa-circle'></i></span>"
          } else if (v == "1") {
            retstr = "<span style='color: grey'><i class='fa fa-circle'></i></span>"
          }
          return retstr;
        }
      }, {
        title: "gnss电量",
        field: "gnssdl",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "蓝牙电量",
        field: "lydl",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "操作",
        field: "dzbqbh",
        events: this.myevents,
        formatter: function (v) {
          let str = "";
          if (that.hascbtns.indexOf("glkz_bqsb") != -1) {
            if (that.s_obj_glxx.sfglsjb == "0") {
              // 关联过的
              str += "<button type='button' class='btn btn-xs btn-warning jcgl_bqsb'><i class='fa fa-unlock'></i>  解除关联</button>";
            } else if (that.s_obj_glxx.sfglsjb == "1") {
              // 未关联过的
              str += "<button type='button' class='btn btn-xs btn-primary gl_bqsb'><i class='fa fa-lock'></i>  关联试卷包</button>";
            }
          }
          if (that.hascbtns.indexOf("ckglxx_bqsb")! - 1) {
            if (that.s_obj_glxx.sfglsjb == "0") {
              str += "<button type='button' class='btn btn-xs btn-primary ckglxx_bqsb'><i class='fa fa-eye'></i>  查看关联信息</button>";
            }
          }
          return str;
        }
      }]
    };
    // this.table_dzbq_glxx.pageSize = 50;
    // this.table_dzbq_glxx.pageList = [50];
    // this.table_dzbq_glxx.hiddenPageinfoLink = true;
    // this.table_dzbq_glxx.paginationLoop = true;
    // this.table_dzbq_glxx.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.table_dzbq_glxx.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    // this.table_dzbq_glxx.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    this.table_dzbq_glxx.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
  }


  @HostListener("window:myevents", ["$event"])
  myevents = {
    "click .toggle": function (e, value, row, index) {
      // 启用状态改变
      if (value === "1") {
        this.updzbqsbZt("0", row, index);
      } else {
        this.updzbqsbZt("1", row, index);
      }
    }.bind(this),
    "click .toggle_gps": function (e, value, row, index) {
      // gps 状态改变
      if (value == "1") {
        this.updzbqsbGPSzt("0", row, index);
      } else {
        this.updzbqsbGPSzt("1", row, index);
      }
    }.bind(this),
    "click .edite_bqsb": function (e, value, row, index) {
      // 编辑
      this.caozuo_dzbqbh = value;
      this.editeFixedField.sfqy = row.sfqy;
      this.editeFixedField.gpskgzt = row.gpskgzt;
      this.edite_bqsb(row);
    }.bind(this),
    "click .remove_bqsb": function (e, value, row, index) {
      // 单条删除
      this.caozuo_dzbqbh = value;
      if (!this.caozuo_dzbqbh) {
        return
      }
      this.commservice.myswal("warning", "确定删除？", "", "cz", () => {
        this.removeDone_bqsb();
      });
    }.bind(this),
    "click .xq_bqsb": function (e, value, row, index) {
      // 详情
      this.caozuo_dzbqbh = value;
      this.xq_bqsb();
    }.bind(this),
    "click .jcgl_bqsb": function (e, value, row, index) {
      // 解除 关联的试卷包
      this.caozuo_dzbqbh = value;
      this.commservice.myswal("warning", "确定解除关联？", "", "cz", () => {
        this.unglzdbqsb();
      });
    }.bind(this),
    "click .gl_bqsb": function (e, value, row, index) {
      //关联试卷包
      this.caozuo_dzbqbh = value;
      this.gldzbqsb();
    }.bind(this),
    "click .ckglxx_bqsb": function (e, value, row, index) {
      //查看关联信息
      const dzbqbhv = row.dzbqbh;
      if (!dzbqbhv) {
        return
      }
      this.viewglxx(dzbqbhv);
    }.bind(this)
  }


  /**
   * 查看电子标签的关联信息（试卷包的信息）
   * @param {string} bh
   */
  viewglxx(bh: string): void {
    const url = "sjgz/jcsjgl/cxglsjbxx";
    this.itservice.kwPtPost(url, {
      ksjhbh: this.s_obj_glxx.ksjhbh,
      cxlx: "dzbqsb",
      bh: bh
    }).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            const glsjbxxListv = resp.glsjbxxList ? resp.glsjbxxList : [];
            this.glsjbxxList = glsjbxxListv;
            $("#viewglxx_Modal").modal({
              keyboard: true,
              backdrop: "static"
            });
          }
        } else {
          this.viewglxx(bh);
        }
      });
    });
  }

  /**
   * 更改电子标签设备状态
   * @param {string} ztv
   * @param row
   * @param index
   */
  updzbqsbZt(ztv: string, row: any, index): void {
    const url = "sjgz/jcsj/scdzSfqy";
    this.itservice.kwPtPost(url, {
      sfqy: ztv,
      sblx: "dzbqsb",
      sbbhs: [row.dzbqbh]
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            $("#table_dzbq_ztxx").bootstrapTable("updateCell", { index: index, field: "sfqy", value: ztv });
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.updzbqsbZt(ztv, row, index);
        }
      });
    })

    // const url = "sjgz/jcsj/dzbqsbxg";
    // this.itservice.kwPtPost(url, {
    //   dzbqbh: row.dzbqbh,
    //   id: row.id,
    //   xh: row.xh,
    //   sfqy: ztv,
    //   gpskgzt: row.gpskgzt
    // }).subscribe(resp => {
    //   this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
    //     if (arg1) {
    //       if (arg2) {
    //         this.commservice.myswal("success", resp, "", "ts", null);
    //         $("#table_dzbq_ztxx").bootstrapTable("updateCell", {index: index, field: "sfqy", value: ztv});
    //       } else {
    //         this.commservice.myswal("warning", resp, "", "ts", null);
    //       }
    //     } else {
    //       this.updzbqsbZt(ztv, row, index);
    //     }
    //   });
    // });
  }

  /**
   * 更改电子标签的 gps状态
   * @param {string} ztv
   * @param row
   * @param {number} index
   */
  updzbqsbGPSzt(ztv: string, row: any, index: number): void {
    const url = "sjgz/sbpz/dzbqSzgpszt";
    this.itservice.kwPtPost(url, {
      gpskgzt: ztv,
      dzbqbhs: [row.dzbqbh],
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            $("#table_dzbq_ztxx").bootstrapTable("updateCell", { index: index, field: "gpskgzt", value: ztv });
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.updzbqsbGPSzt(ztv, row, index);
        }
      });
    });
  }

  /**
   * 单条删除标签设备
   */
  removeDone_bqsb(): void {
    const url = "sjgz/jcsj/dzbqsbsc";
    this.itservice.kwPtPost(url, {
      dzbqbhs: [this.caozuo_dzbqbh]
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
            this.commservice.myswal("success", resp, "", "ts", null);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.removeDone_bqsb();
        }
      });
    })
  }

  /**
   * 标签设备详情
   */
  xq_bqsb(): void {
    if (!this.caozuo_dzbqbh) {
      return
    }
    const url = "sjgz/jcsj/dzbqsbxq";
    this.itservice.kwPtPost(url, {
      dzbqbh: this.caozuo_dzbqbh
    }).subscribe(resp => {
      this.commservice.handResponse("get", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            resp["sfqymc"] = (resp.sfqy == "0") ? "未启用" : "已启用";
            resp["gpskgztmc"] = (resp.gpskgzt == "0") ? "未开启" : '已开启';
            // resp["zxztmc"] = (resp.zxzt == "0") ? "在线" : "离线";
            this.xqobj_bqsb = {
              from: "bqsb",
              keyValue: resp
            };
            $("#xq_bqsbModal").modal({
              keyboard: true,
              backdrop: "static"
            });
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.xq_bqsb()
        }
      });
    });
  }

  /**
   * 解除关联试卷包
   */
  unglzdbqsb(): void {
    const url = "sjgz/jcsjgl/jcSjbdzbqgl";
    this.itservice.kwPtPost(url, {
      dzbqbh: this.caozuo_dzbqbh,
      ksjhbh: this.s_ksjhbh
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_dzbq_glxx = Object.assign({}, this.table_dzbq_glxx);
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.unglzdbqsb();
        }
      });
    })
  }

  /**
   * 关联试卷包
   */
  gldzbqsb(): void {
    this.s_obj_sjb.sjbmc = "";
    this.s_obj_sjb.mdkdmc = "";
    this.s_obj_sjb.mdkqmc = "";
    this.table_sjb = Object.assign({}, this.table_sjb);
    $("#glsjb_Modal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  /**
   * 关联试卷包
   */
  sure_glsjb(): void {
    const selectrow = $("#table_sjb").bootstrapTable("getSelections");
    if (!selectrow.length) {
      this.commservice.myswal("warning", "请选择要关联的试卷包", "", "ts", null);
      return
    }
    this.commservice.blockUI({
      boxed: true,
      message: "保存中...",
      zIndex: 10051,
      overlayColor: "#67809F"
    });
    const sjbbhv = selectrow[0].sjbbh;
    const dzbqbhv = this.caozuo_dzbqbh;
    const url = "sjgz/jcsjgl/dzbqGlsjb";
    this.itservice.kwPtPost(url, {
      dzbqbh: dzbqbhv,
      sjbbh: sjbbhv,
      ksjhbh: this.s_ksjhbh
    }).subscribe(resp => {
      this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
        if (arg1) {
          if (arg2) {
            this.commservice.myswal("success", resp, "", "ts", null);
            this.table_dzbq_glxx = Object.assign({}, this.table_dzbq_glxx);
            $("#glsjb_Modal").modal("hide");
          } else {
            this.commservice.myswal("warning", resp, "", "ts", null);
          }
        } else {
          this.sure_glsjb();
        }
      });
    });
  }

  /**
   * 编辑标签设备
   * @param row
   */
  edite_bqsb(row: any): void {
    this.modalflag = "edite";
    this.modaltitle = "编辑标签设备";
    this.formgroup_bqsb.patchValue({
      idCtr: row.id,
      xhCtr: row.xh
    });
    $("#add_bqsbModal").modal({
      keyboard: true,
      backdrop: "static"
    });
  }

  createformgroup_bqsb(): void {
    this.formgroup_bqsb = this.fb.group({
      idCtr: ["", [this.myValidator.myrequired('标签设备id')]],
      xhCtr: ["", [this.myValidator.myrequired("标签设备型号")]]
    });
  }


  sure_bqsb(): void {
    if (!this.formgroup_bqsb) {
      const ctrols = this.formgroup_bqsb.controls;
      for (let path in ctrols) {
        ctrols[path].markAsDirty();
        ctrols[path].updateValueAndValidity();
      }
      return
    }
    const formgroupv = this.formgroup_bqsb.getRawValue();
    const idv = this.commservice.removeSpace(true, formgroupv.idCtr);
    const xhv = this.commservice.removeSpace(true, formgroupv.xhCtr);

    const flag = this.modalflag;
    this.commservice.blockUI({
      boxed: true,
      message: "保存中...",
      zIndex: 10051,
      overlayColor: "#67809F"
    });
    if (flag == "add") {
      const url = "sjgz/jcsj/dzbqsbxz";
      this.itservice.kwPtPost(url, {
        id: idv,
        xh: xhv
      }).subscribe(resp => {
        this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
          if (arg1) {
            if (arg2) {
              this.commservice.myswal("success", resp, "", "ts", null);
              this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
              $("#add_bqsbModal").modal("hide");
            } else {
              this.commservice.myswal("warning", resp, "", "ts", null);
            }
          } else {
            this.add_bqsb();
          }
        });
      });
    } else if (flag == "edite") {
      const url = "sjgz/jcsj/dzbqsbxg";
      this.itservice.kwPtPost(url, {
        dzbqbh: this.caozuo_dzbqbh,
        id: idv,
        xh: xhv,
        sfqy: this.editeFixedField.sfqy,
        gpskgzt: this.editeFixedField.gpskgzt
      }).subscribe(resp => {
        this.commservice.handResponse("put", url, resp, (arg1, resp, arg2) => {
          if (arg1) {
            if (arg2) {
              this.commservice.myswal("success", resp, "", "ts", null);
              this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
              $("#add_bqsbModal").modal("hide");
            } else {
              this.commservice.myswal("warning", resp, "", "ts", null);
            }
          } else {
            this.add_bqsb();
          }
        });
      })
    }
  }


  /**
   * 供关联的试卷包选择
   */
  inittable_sjb(): void {
    this.table_sjb = {
      tableid: "table_sjb",
      url: "sjgz/jcsj/sjbxxlb",
      reqobj: this.s_obj_sjb,
      sidePagination: "server",
      pageSize: 10,
      pageList: [10, 20, 30],
      total: "totalRows",
      rows: "sjbxxList",
      height: 500,
      columns: [{
        radio: true
      }, {
        title: "试卷包名称",
        field: "sjbmc",
        cellStyle: function () {
          return {
            classes: 'td1'
          }
        }
      }, {
        title: "目的地考点名称",
        field: "mdkdmc",
        cellStyle: function () {
          return {
            classes: 'td2'
          }
        }
      }, {
        title: "目的地考区名称",
        field: "mdkqmc",
        cellStyle: function () {
          return {
            classes: 'td3'
          }
        }
      }, {
        title: "试卷袋数量",
        field: "sjdsl",
        cellStyle: function () {
          return {
            classes: 'td4'
          }
        }
      }]
    };
    // this.table_sjb.pageSize = 50;
    // this.table_sjb.pageList = [50];
    // this.table_sjb.hiddenPageinfoLink = true;
    // this.table_sjb.paginationLoop = true;
    // this.table_sjb.paginationPreText = "<i class='fa fa-arrow-left'></i>上一页";
    // this.table_sjb.paginationNextText = "下一页<i class='fa fa-arrow-right'></i>";
    // this.table_sjb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
    this.table_sjb.height = this.commservice.getViewPort().height - this.commservice.topH - this.commservice.topmenuH - 240 - 110;
  }

  /**
   * 电子标签关联试卷包的表格查询条件
   */
  createsearchForm_glxx(): void {
    const gpskgztdata = [{
      code: "",
      name: "--请选择--"
    }, {
      code: "0",
      name: '未开启'
    }, {
      code: "1",
      name: "已开启"
    }];

    const sfglsjbData = [{
      code: "1",
      name: '未关联',
    }, {
      code: "0",
      name: "已关联"
    }];


    $("#gpskqztSelect").empty();
    $("#sfglsjbSelect").empty();
    let str_gpskqzt: string = "", str_sfglsjb = "";
    gpskgztdata.forEach((item) => {
      str_gpskqzt += "<option value='" + item.code + "'>" + item.name + "</option>";
    });
    sfglsjbData.forEach((item) => {
      str_sfglsjb += "<option value='" + item.code + "'>" + item.name + "</option>";
    });
    $("#gpskqztSelect").append(str_gpskqzt);
    $("#sfglsjbSelect").append(str_sfglsjb);
    $("#gpskqztSelect").selectpicker({
      size: 5
    });
    $("#sfglsjbSelect").selectpicker({
      size: 5
    });
    this.selectDefaultField.gpskgzt = gpskgztdata[0].code;
    this.selectDefaultField.sfglsjb = sfglsjbData[0].code;

    // 状态信息 tab的搜索条件
    $("#gpskqztSelect2").empty();
    let str_gpskqzt2: string = "";
    gpskgztdata.forEach((item) => {
      str_gpskqzt2 += "<option value='" + item.code + "'>" + item.name + "</option>";
    });

    $("#gpskqztSelect2").append(str_gpskqzt2);
    $("#gpskqztSelect2").selectpicker({
      size: 5
    });
    this.selectDefaultField.gpskgzt2 = gpskgztdata[0].code;

  }

  /**
   * 获取用户信息
   */
  getuserinfo(): void {
    this.commservice.getUserinfo((info) => {
      this.userinfo = info;
      this.initactions(); //用户按钮权限
    });
  }

  initUploader(): void {
    // const filealias = "tysjdrwj";
    this.uploader = new FileUploader({
      url: `${this.commservice.uploadFileurl}sjgz/jcsj/dzbqsbplxz`,
      method: "POST",
      // itemAlias: filealias,
      autoUpload: false,//选择文件后，自动上传
    });
    const pubheaderparams1 = this.commservice.getpubheaderParams1(null);
    const pubheaderparams2 = this.commservice.getpubheaderParams2();
    this.uploader.setOptions({
      headers: [{
        name: "xc_client_sessionid",
        value: pubheaderparams1.signkey
      }, {
        name: "Content-Signature",
        value: pubheaderparams1.signreqobj
      }, {
        name: 'xc_sso_sessionid',
        value: pubheaderparams2.access_token
      }, {
        name: "Authorization",
        value: pubheaderparams2.Authorization
      }],
      //allowedFileType: this.o.allowedFileType,
    });
  }

  initUploaderEvents() {
    this.uploader.onBuildItemForm = this.buildItemForm.bind(this);
    this.uploader.onAfterAddingFile = this.afterAddFile.bind(this);
    this.uploader.onWhenAddingFileFailed = this.whenAddFileFailed.bind(this);
    this.uploader.onProgressItem = this.onProgress.bind(this);
    this.uploader.onSuccessItem = this.successItem.bind(this);
  }

  buildItemForm(fileItem: FileItem, form: any): void {

  }

  selectedFileOnChanged(e: any): void {

  }

  afterAddFile(file: FileItem): void {
    // 对选择的dbf文件，做严格控制
    const filename = file.file.name;
    this.filewarnflag = false;
    this.filewarntext = "";
    this.nowfile = file;
    this.nowfilename = filename;
  }

  /**
   * 选择文件失败的回调
   * @param {FileLikeObject} item
   * @param filter
   * @param options
   */
  whenAddFileFailed(item: FileLikeObject, filter: any, options: any): void {
    // this.filewarnflag = true;
    // this.filewarntext = "文件格式不正确";
  }

  /**
   * 上传进度
   * @param {FileItem} fileItem  上传的文件
   * @param progress     该文件的上传进度
   * @returns {any}
   */
  onProgress(fileItem: FileItem, progress: any): any {

  }

  pldrDone(): void {
    if (!this.nowfile) {
      this.filewarnflag = true;
      this.filewarntext = "请选择导入数据文件";
      return
    }
    this.filewarnflag = false;
    this.filewarntext = "";

    this.commservice.myswal("warning", "确定导入文件内容?", "", "cz", () => {
      this.commservice.blockUI({
        boxed: true,
        message: "数据导入中...",
        zIndex: 10051,
        overlayColor: "#67809F"
      });
      this.uploader.uploadItem(this.nowfile);
    });
  }

  /**
   * 上传成功后 的回调
   * @param {FileItem} item
   * @param {string} response
   * @param {number} status
   * @param {ParsedResponseHeaders} headers
   */
  successItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
    if (status == 200) {
      const respbody = JSON.parse(response);
      const ywcode = respbody.code; // 业务接口code 【8001(signkey 失效)】,【 200】【其他的失败直接抛出 message】
      const ywmsg = respbody.message; // 业务接口提示信息
      const ywresult = respbody.result;// 业务接口返回的数据
      if (ywcode == 200) {
        this.commservice.unblockUI(false);
        $("#pldr_Modal").modal("hide");
        this.table_dzbq_ztxx = Object.assign({}, this.table_dzbq_ztxx);
      } else {
        this.commservice.unblockUI(false);
        this.commservice.myswal("warning", ywmsg, "", "ts", null);
      }
    } else {
      // 上传文件后获取服务器返回的数据错误
      this.commservice.unblockUI(false);
      this.commservice.myswal("warning", "导入出错", "", "ts", null);
    }
  }

  constructor(private localstorage: LocalStorageService,
    private commservice: CommService,
    private itservice: MyhttpService,
    private fb: FormBuilder,
    private myValidator: MyValidator) {

  }

  ngOnInit() {
    this.pagetitleobj = sjgzxinModuledatas.bqsbgl;
    this.s_ksjhbh = this.localstorage.get("hksjh");
    this.s_obj_glxx.ksjhbh = this.s_ksjhbh;
    this.s_obj_sjb.ksjhbh = this.s_ksjhbh;
    this.getuserinfo();
    this.inittable_dzbqsb_ztxx();
    this.createsearchForm_glxx();
    this.createformgroup_bqsb();
    //关联的试卷包
    this.inittable_sjb();
    // 批量设置电子标签参数
    this.createformgroup_cspz();
    this.initUploader();
    this.initUploaderEvents();
  }

  ngOnDestroy() {

  }

}
